/*
 * ThreadPool.cpp
 *
 *  Created on: Jul 15, 2024
 *      Author: root
 */

#define TAG "thread_pool"
#include "all_header.h"
namespace bsp {

///////// test
static void aaa1() {
	LOG_D("this is aaa1" NL);
}

void aaa2(int v) {
	LOG_D("this is aaa2 %d" NL, v);
}

//auto aaa3() {
//	return std::bind(&ThreadPool::aaa2, this, 77);
//}

void ThreadPool::test1() {
	ThreadPool thd(3, 100);
	thd.open();
	thd.addFunc(aaa1);
//	thd.addFunc(thd.aaa3());
	getchar();
}

class Client {
private:
	int fd;

	std::string str;

public:
	int getFd() {
		return fd;
	}
	void setFd(int fd) {
		this->fd = fd;
	}

	Client(int fd) :
			fd { fd } {
		LOG_D("client on construct" NL);
	}
	~Client() {
		LOG_D("client on destroy" NL);
	}

	void read(Client *c) {
		LOG_D("fd %d, str %p" NL, c->fd, c->str.c_str());
	}
	void write() {
		LOG_D("fd %d, str %p" NL, fd, &str);
	}
};

void bbb(Client &client) {
	LOG_D("bbb %d" NL, client.getFd());
}

template<class F>
void add(F &&fn) {
	LOG_D("add fun" NL);
	std::queue<std::function<void()>> funcs;
	funcs.push(std::forward<F>(fn));
}

void ThreadPool::test2() {
	ThreadPool thd(3, 100);
	thd.open();

	Client client(3);

	auto a1 = std::bind(&Client::read, client, &client);
	add(a1);
//	a1();
//	client.setFd(4);
//	a1();

//	thd.addFunc(aa);
//	thd.addFunc(std::bind(&Client::write, client));
	getchar();
}
}

